//
// Created by sxt on 2023/10/19.
//

#ifndef MY_REFLECT_WORK_EXECUTOR_H
#define MY_REFLECT_WORK_EXECUTOR_H

#include <iostream>
#include <MyException.h>
#include <TypeDescriptor.h>

/**
 * 工作执行器
 */
class WorkExecutor {
public:
    /**
     * 执行任务
     */
    void execute() { // NOLINT
        if (taskType.empty() || taskName.empty()) {
            throw myreflect::MsgException("任务类型或任务名称不能为空");
        }
        std::cout << "执行任务: 处理针对于: " << taskName << "的" << taskType << "类型的任务" << std::endl;
        if (nextWorkExecutor != nullptr) {
            nextWorkExecutor->execute();
        }
    }

    void addNext(WorkExecutor *next) {
        nextWorkExecutor.reset(next);
    }

private:
    /**
     * 任务名称
     */
    std::string taskName;

    /**
     * 任务类型
     */
    std::string taskType;

    /**
     * 下一个任务执行器
     */
    std::unique_ptr<WorkExecutor> nextWorkExecutor{nullptr};

public:
    static void makeReflectable() {
        REGISTER_CLASS(WorkExecutor)
                .addField("taskName", &WorkExecutor::taskName)
                .addField("taskType", &WorkExecutor::taskType)
                .addMethod("addNext", &WorkExecutor::addNext);
    }
};


#endif //MY_REFLECT_WORK_EXECUTOR_H
